Matplotlib.pyplot is a state-based interface to matplotlib. It provides an implicit, MATLAB-like, way of plotting. It also opens figures on your screen, and acts as the figure GUI manager.
| Age | Weight |
|---|---|
| 1 | 1.2 |
| 2 | 2 |
| 3 | 5 |
| 4 | 4 |
import matplotlib.pyplot as plt
plt.figure(figsize=(10, 5))
plt.plot([0, 1, 2, 3, 4], [0,1.2, 2, 5, 4], 'g-', label='Rat Weight')
plt.title('Average Rat Weight/Age')
plt.xlabel('Rat Age')
plt.ylabel('Rat Weight')
plt.xlim(0, 5)
plt.ylim(0, 20)
plt.grid(True)
plt.legend()
plt.show()
import numpy as np
plt.style.use('_mpl-gallery')
x = 0.5 + np.arange(8)
y = [4.8, 5.5, 3.5, 4.6, 6.5, 6.6, 2.6, 3.0]
fig, ax = plt.subplots()
ax.stem(x, y)
ax.set(xlim=(0, 8), xticks=np.arange(1, 8),
ylim=(0, 8), yticks=np.arange(1, 8))
plt.show()
import plotly
import plotly.express as px
plotly.offline.init_notebook_mode()
df = px.data.tips()
fig = px.pie(df, values='tip', names='day')
fig.show()
import plotly.graph_objects as go
np.random.seed(1)
N = 70
fig = go.Figure(data=[go.Mesh3d(x=(70*np.random.randn(N)),
y=(55*np.random.randn(N)),
z=(40*np.random.randn(N)),
opacity=0.5,
color='green'
)])
fig.update_layout(
scene = dict(
xaxis = dict(nticks=4, range=[-100,100],),
yaxis = dict(nticks=4, range=[-50,100],),
zaxis = dict(nticks=4, range=[-100,100],),),
width=700,
margin=dict(r=20, l=10, b=10, t=10))
fig.show()
from PIL import Image
img = Image.open('ideogram.jpeg')
fig = plt.imshow(img)
plt.axis('off')
(-0.5, 1023.5, 1023.5, -0.5)